package com.itheima.methodreference;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

public class Demo4 {
    public static void main(String[] args) {

        //构造器引用
        //格式：类名::new
        /*CarFactory cf = new CarFactory() {
            @Override
            public Car getCar(String name) {
                return new Car(name);
            }
        };*/

        //CarFactory cf = name-> new Car(name);

        //如果这个Lambda表达式里只是在创建对象，并且"->"前后参数的形式一致，就可以使用构造器引用
        CarFactory cf = Car::new;

        Car c1 = cf.getCar("宝马");
        System.out.println(c1);

    }
}

@FunctionalInterface
interface CarFactory {
    Car getCar(String name);
}

@Data
@NoArgsConstructor
@AllArgsConstructor
class Car {

   private String name;
}